package com.leapp.sk.viewdelegate.task

import android.content.Context
import android.support.v7.app.AppCompatActivity
import android.text.TextUtils
import android.view.View
import android.widget.ImageView
import android.widget.LinearLayout
import cc.vv.lkbasecomponent.util.LKScreenUtil
import com.example.mvp.delegate.BaseAppDelegate
import com.example.mvp.view.NoScrollGridView
import com.example.mvp.view.SKTopBar
import com.leapp.sk.R
import com.leapp.sk.bean.CompleteTaskEntity
import com.leapp.sk.ui.activity.AppMainTableActivity
import com.leapp.sk.ui.activity.task.ParentingTaskActivity
import com.leapp.sk.ui.activity.task.TaskDetialActivity
import com.leapp.sk.ui.adapter.CompleteTaskAdapter

/**
 * 作业详情视图托管类
 * @author  chaohaipeng  on 2018/8/9.
 */
class TaskDetialDelegate :BaseAppDelegate(){
    /**
     * 语音适配器
     */
    private var voiceAdapter:CompleteTaskAdapter?=null

    override fun initWidget() {
    }

    override fun initLayoutRes(): Int {
        return R.layout.activity_task_detial
    }
  fun initAdapter(mlist: MutableList<CompleteTaskEntity>,isVoice:Boolean){
      val gv_task_detial_list = getView<NoScrollGridView>(R.id.gv_task_detial_list)
      voiceAdapter = CompleteTaskAdapter(getActivity(), mlist,true)
      gv_task_detial_list.adapter=voiceAdapter
      if (isVoice){
          gv_task_detial_list.numColumns=1
      }else{
          gv_task_detial_list.numColumns=3
      }


  }

    /**
     * 初始化星级
     */
     fun initFlowerCount(context: Context,count: Int) {
      val  ll_atd_flower= getView<LinearLayout>(R.id.ll_atd_flower)
        for (i in 0..count) {
            val view= View.inflate(context, R.layout.layout_flwoer_image, null)
           val image=view.findViewById<ImageView>(R.id.iv_lfi_flwoer)
            image.setImageResource(R.mipmap.icon_flower)
            val margin = LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.WRAP_CONTENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT)
            // 设置切换点 距离
            margin.setMargins(LKScreenUtil.dp2px(10f), 0, 0, 0)
            ll_atd_flower.addView(view, margin)
        }
    }

    /**
     * 设置标题
     */
    fun setTitle(title:String?){
        val topBar= getView<SKTopBar>(R.id.jtb_task_detial)
        if (!TextUtils.isEmpty(title)){
            topBar?.setTitle(title)
        }
        setEvent(topBar)
    }
    /**
     * 设置设置事件
     */
    private  fun setEvent(topBar: SKTopBar){
        topBar?.setEventInterface(object : SKTopBar.EventInterface{
            override fun leftOnClick() {
                getActivity<TaskDetialActivity>().finish()

            }
            override fun rightOnClick() {
            }

        })
    }
}